<template>
  <a-drawer
    placement="right"
    title="编辑系统配置"
    :width="700"
    @close="handleClose"
    :visible="visible"
    :bodyStyle="{paddingBottom: '80px'}"
  >
    <config-form ref="configForm" mode="edit" ></config-form>
    <div
      :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
        }"
    >
      <a-button :style="{marginRight: '8px'}" @click="handleClose">取消</a-button>
      <a-button @click="handleSubmit" type="primary">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>

  import {updateSysConfig} from "@/api/sysConfig"
  import ConfigForm from "./ConfigForm"


  export default {

    components: {
      ConfigForm
    },

    data() {
      return {
        visible: false,
        row: {},
        index: null,
        productId: null,
      }
    },

    methods: {
      open(row, index) {
        this.row = row
        this.index = index
        this.visible = true
        this.$nextTick(()=>{
          this.$refs.configForm.setFormData(row)
        })
      },
      handleClose() {
        this.visible = false;
      },
      handleSubmit() {
        this.$refs.configForm.getFormData().then(data=>{
          updateSysConfig(data).then(() => {
            this.$emit('success', data, this.index)
            this.visible = false;
          })
        })
      },
    }

  }
</script>

<style lang="less" scoped>
</style>
